package com.tianji.learning.controller.api;


import com.tianji.learning.entity.vo.LearningLessonVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "我的课程远程调用接口")
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("lessons")
public class LearningLessonApi {

    private final ILearningLessonService learningLessonService;

    // 校验课程是否有效
    @ApiOperation("给媒资模块使用，校验课程是否有效")
    @GetMapping("{courseId}/valid")
    public Long isLessonValid(@PathVariable("courseId") Long courseId) {
        // 如果课程有效，返回lessonId，否则返回null
        return learningLessonService.isLessonValid(courseId);
    }

    /**
     * 查询当前用户的课表中是否有该课程，如果有该课程则需要返回课程的学习进度、课程有效期等信息。
     *
     * @param courseId
     * @return
     */
    @ApiOperation("查询课程详情")
    @GetMapping("{courseId}")
    public LearningLessonVO queryLesson(@PathVariable("courseId") Long courseId) {
        return learningLessonService.queryLesson(courseId);
    }

    @ApiOperation("给课程模块的统计学习该课程的报名人数不需要知道过期没过期")
    @GetMapping("{courseId}/count")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId) {
        return learningLessonService.countLearningLessonByCourse(courseId);
    }
}
